<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html lang="en">
<head>
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>学生列表</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/statics/css/bootstrap.min.css">
    <style>
        .form-control {
            height: 30px;
        }

        .pagination {
            margin-top: 0px;
        }
    </style>
    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/js/jquery-1.8.3.min.js"></script>

</head>
<body>
<div class="container-fluid">
    <div class="row">
        <div class="col-sm-12" style="text-align: center">
            <form class="form-inline"
                  action="${pageContext.request.contextPath}/student/showByNameOrPhoneOrQQ?pageNumber=1" method="post">
                <div class="form-group">
                    <label>请选择:</label>
                    <select class="form-control" style="height: 30px; width: 100px;" name="selectName">
                        <option value="name">姓名</option>
                        <option value="phone">手机</option>
                        <option value="qq">QQ</option>
                    </select>
                    <input type="text" class="form-control" name="selectVal" style="height: 30px; width: 300px;">
                </div>

                <button type="submit" class="btn btn-primary btn-sm">搜索</button>
            </form>
        </div>
    </div>
    <div class="row" style="margin-top: 15px;height: 300px">
<c:if test="${sessionScope.user.role==1}">
        <div class="col-sm-12" style="margin-bottom: 10px;">
            <a href="${pageContext.request.contextPath}/student/showMsg" class="btn btn-sm btn-success">添加学生信息</a>
        </div>
</c:if>
        <div class="col-sm-12">
            <table class="table table-hover table-bordered table-striped">
                <thead>
                <tr>
                    <th>姓名</th>
                    <th>电话</th>
                    <th>QQ</th>
                    <th>年龄</th>
                    <th>生日</th>
                    <th>生肖</th>
                    <th>星座</th>
                    <th>班级</th>
                    <th>小组</th>
                    <th>就业城市</th>
                    <th>标签</th>
                    <th>操作</th>
                </tr>
                </thead>
                <%--展示学生--%>
                <c:forEach var="s" items="${requestScope.students}">
                    <tr>
                        <td>${s.sname}</td>
                        <td>${s.sphone}</td>
                        <td>${s.sqq}</td>
                        <td>${s.sage}</td>
                        <td>
                            <fmt:formatDate value="${s.sbirthday}" pattern="yyyy年mm月dd日"></fmt:formatDate>
                        </td>
                        <td>${s.sattribute}</td>
                        <td>${s.sstars}</td>
                        <td>${s.clazz.cname}</td>
                        <td>${s.group.gname}</td>
                        <td>${s.city.cname}</td>
                        <td>
                            <c:forEach var="m" items="${s.marks}">
                                ${m.mname}
                            </c:forEach>
                        </td>
                        <c:if test="${sessionScope.user.role==1}">
                            <td>
                                <a href="${pageContext.request.contextPath}/student/showStudent?student.sid=${s.sid}"
                                   class="btn btn-warning btn-sm">修改</a>
                                    <%-- ${s.sid}是删除学生的id传入方法中
                                    javascript:是表示在触发默认动作时，执行一段JavaScript代码，
                                    而 javascript:; 表示什么都不执行，这样点击时就没有任何反应。
                                    --%>

                                <a href="javascript:;" class="btn btn-danger btn-sm" onclick="del(${s.sid})">删除</a>
                            </td>
                        </c:if>
                    </tr>
                </c:forEach>

            </table>
        </div>
    </div>

    <c:if test="${requestScope.total!=0}">
        <div class="row">
            <div class="col-sm-8">
                <a href=""
                   class="btn btn-sm btn-info">下载学生信息到文件中</a>
            </div>
            <div class="col-sm-4">
                <nav aria-label="Page navigation">
                    <ul class="pagination">
                        <li>
                            <c:if test="${requestScope.pageNumber>1}">
                                <a href="${pageContext.request.contextPath}/student/page?pageNumber=${requestScope.pageNumber-1}"
                                   aria-label="Previous">
                                    <span aria-hidden="true">&laquo;</span>
                                </a>
                            </c:if>
                            <c:if test="${requestScope.pageNumber<=1}">
                                <span aria-hidden="true">&laquo;</span>
                            </c:if>
                        </li>
                        <li>
                            <c:forEach begin="1" var="page" end="${requestScope.totalPage}">
                                <a href="${pageContext.request.contextPath}/student/page?pageNumber=${page}">${page}</a>
                            </c:forEach>
                        </li>

                        <li>
                            <c:if test="${requestScope.pageNumber<requestScope.totalPage}">
                                <a href="${pageContext.request.contextPath}/student/page?pageNumber=${requestScope.pageNumber+1}"
                                   aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                </a>
                            </c:if>
                            <c:if test="${requestScope.pageNumber>=requestScope.totalPage}">
                                <span aria-hidden="true">&raquo;</span>
                            </c:if>
                        </li>
                    </ul>
                </nav>
            </div>
        </div>
    </c:if>
</div>
</body>
</html>
<script>
    function del(sid) {
        if (window.confirm("你确定删除这条学生信息吗？")) {
//sid是形参，将sid传入链接进行传值
            location.href = "${pageContext.request.contextPath}/student/dropStudent?student.sid=" + sid;
        }
    }
</script>